package com.lh.api.controller.shop;

import com.lh.api.controller.AbstractController;
import com.lh.api.service.ShopService;
import com.lh.api.vo.SearchVo;
import com.lh.api.vo.ShopDetailVo;
import com.lh.common.enums.ShopTypeEnum;
import com.lh.common.enums.ShopSortTypeEnum;
import com.lh.common.utils.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Gze
 * @ClassName: ShopAction
 * @Description: (商品管理)
 * @date: 2020-05-15 11:07
 */

@Api(value="ShopAction",tags={"商品相关接口 v1.3"})
@RestController
@RequestMapping("/api/shop")
public class ShopAction extends AbstractController {

    @Autowired
    private ShopService shopService;

    @ApiOperation(value = "商品列表 v1.3")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query", name = "sortType", value = "商品排序类型：DEFAULT:默认 时间排序，PRICEDESC:价格从高到底，PRICEASC:价格从低到高 v1.3", required = false, dataTypeClass = ShopSortTypeEnum.class),
            @ApiImplicitParam(paramType="query", name = "shopType", value = "商品类型：ONE:一元抢购，SHOP:普通商品", required = true, dataTypeClass = ShopTypeEnum.class),
            @ApiImplicitParam(paramType="query", name = "qureyTime", value = "查询时间,形如:2020-03-01 21:00:00,查询第一页时不用传，由后端返回", required = false,dataTypeClass= Integer.class),
            @ApiImplicitParam(paramType="query", name = "pageNum", value = "当前页", required = true,dataTypeClass= Integer.class),
            @ApiImplicitParam(paramType="query", name = "pageSize", value = "页数大小", required = true,dataTypeClass= Integer.class)
    })
    @GetMapping(value = "/list")
    @ResponseBody
    public Result<SearchVo> indexShop(ShopSortTypeEnum sortType, ShopTypeEnum shopType, String qureyTime, Integer pageNum, Integer pageSize){
        if(pageNum != null && pageNum == 1){
            qureyTime = DateTimeUtil.getDateTime();
        }
//        else {
//            AssertUtil.assertNotNull(qureyTime, Constant.RESULT.FI1000, "QureyTime is required");
//        }
//        PageUtils<SearchVo> searchVoPageUtils = shopService.getlist(qureyTime, shopType, pageNum, pageSize);
        PageUtils<SearchVo> searchVoPageUtils = shopService.getlist(qureyTime, sortType, shopType, pageNum, pageSize);
        searchVoPageUtils.setQureyTime(qureyTime);
        return Result.ok(searchVoPageUtils);
    }

    @ApiOperation(value = "普通商品详情页面")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query", name = "sid", value = "商品id", required = true, dataTypeClass= Long.class),
    })
    @GetMapping("/getShopDetail")
    @ResponseBody
    public Result<ShopDetailVo> getShopDetail(Long sid){
        AssertUtil.assertNotNull(sid, Constant.RESULT.FI1000, "sid is required");
        ShopDetailVo shopDetailVo = shopService.getShopDetail(sid, getUserId());
        return Result.ok(shopDetailVo);
    }

    @ApiOperation(value = "获取推荐商品列表 v1.3")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query", name = "qureyTime", value = "查询时间,形如:2020-03-01 21:00:00,查询第一页时不用传，由后端返回", required = false,dataTypeClass= Integer.class),
            @ApiImplicitParam(paramType="query", name = "pageNum", value = "当前页", required = true,dataTypeClass= Integer.class),
            @ApiImplicitParam(paramType="query", name = "pageSize", value = "页数大小", required = true,dataTypeClass= Integer.class)
    })
    @GetMapping(value = "/getRecommendShopList")
    @ResponseBody
    public Result<SearchVo> recommendShop(String qureyTime, Integer pageNum, Integer pageSize){
        if(pageNum != null && pageNum == 1){
            qureyTime = DateTimeUtil.getDateTime();
        }
        PageUtils<SearchVo> searchVoPageUtils = shopService.getRecommendShopList(qureyTime, pageNum, pageSize);
        searchVoPageUtils.setQureyTime(qureyTime);
        return Result.ok(searchVoPageUtils);
    }
}
